const { mysql } = require('../qcloud')

async function goodsList (ctx) {
    const {categoryId, pageSize, page} = ctx.request.query

    // const currentCategory = await mysql("nideshop_category").where({
    //   "parent_id": categoryId
    // }).select()

    // var categoryList = []

    // // 筛选出子分类列表
    // for (let category of currentCategory) {
    //   categoryList.push(category.id)
    // }

    // console.log(categoryList)

    const goodsList = await mysql('nideshop_goods')
        .where({
            'category_id': categoryId
        })
        .select()
        .limit(pageSize)
        .offset(Number(page) * pageSize)

    ctx.state.data = {
        goodsList
    }
}

module.exports = {
    goodsList
}
